package com.miniprogram.common.enums;

import com.miniprogram.bean.vo.EnumVo;

import java.util.ArrayList;
import java.util.List;

/**
 * 支付类型
 *
 * @author lin
 * @since 2020年1月5日
 */
public enum PayTypeEnum {

    // 普通支付
    NORMAL(1, "order_normal", "微信普通支付"),
    // VIP支付
    VIP(2, "order_vip", "VIP支付"),
    // 雷神vip支付
    THUNDER(3, "order_thunder", "雷神VIP支付"),
    // 充值雷神
    RECHARGE_THUNDER(4, "recharge_thunder", "微信充值雷神会员"),
    // 充值普通会员
    RECHARGE_VIP(5, "recharge_thunder", "微信充值普通会员"),
    // 小卖店商品支付
    GOODS(6, "goods", "微信购买上小卖店商品");

    private Integer code;

    private String enCode;

    private String description;

    private final static String FLAG = "_";

    PayTypeEnum(Integer code, String enCode, String description) {
        this.code = code;
        this.enCode = enCode;
        this.description = description;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public static PayTypeEnum ValueOfName(String name) {
        for (PayTypeEnum orderTypeEnum : PayTypeEnum.values()) {
            if (orderTypeEnum.code.equals(name)) {
                return orderTypeEnum;
            }
        }
        return null;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static List<EnumVo> getAll() {
        List<EnumVo> list = new ArrayList<>();
        for (PayTypeEnum restStatusEnum : PayTypeEnum.values()) {
            EnumVo vo = new EnumVo();
            vo.setCode(restStatusEnum.getCode());
            vo.setDescription(restStatusEnum.getDescription());
            list.add(vo);
        }
        return list;
    }

    /**
     * 从字符串中拆除订单id
     */
    public String getOrderNum(String orderNum) {
        return orderNum.replace(enCode + FLAG, "");
    }

    /**
     * 整理出给微信发的订单id
     */
    public String formatOrderNum(Integer orderId) {
        return enCode + FLAG + orderId;
    }


}
